import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  modules: {},
  state: {
    TOKEN: null,
    msg: { name: 'a123' },
    user: {
      userName: '',
      userPwd: '',
    },
    m3u8: '',
    rtmp: '',
    objRoom: {
      roomId: '',
      companyDepartmentId: '', //公司id
      roomName: '', //房间名称
      roomGonggao: '', //房间公告
      roomBgImg: '', //直播间封面
      roomShortInfo: '', //直播间简介
      videoLiveUrl: '', //直播地址
      videoLiveUrlRtmp: '', //
      videoTitleInfo: '', //摘要
      videoLiveHtml: '', //房间访问的html页面地址
      onlineUserCountMul: 50, //在线人数的倍数
      isReview: false, //是否开启审核
      roomType: 0, //（弃用)房间类型：0=销售直播间，1=客服直播间
      room_Type2: 0, //0=直播间，1=录播间
      room_User: 0, //房间使用角色：0=销售，1=客服
      wechatUrl: '', //小程序地址
      buyHtml: '', //购买地址
      addTime: '', //($date-time)
      editTime: '', //($date-time)
    },
  },
  getters: {
    getValue: (state) => (key) => {
      return state[key];
    },
    getTOKEN: (state) => {
      if (state.TOKEN === null) {
        state.TOKEN = localStorage.getItem('TOKEN') || null;
      }
      return state.TOKEN;
    },
    getUser: (state) => {
      return state.user;
    },
  },
  mutations: {
    setValue: (state, obj) => {
      state[obj.key] = obj.value;
    },
    setLocal: (state, value) => {
      state.key = value;
      localStorage.setItem('key', value);
    },
    setUser: (state, obj) => {
      state.user.userName = obj.userName;
      state.user.userPwd = obj.userPwd;
    },
    setRoom: (state, obj) => {
      state.objRoom = { ...state.objRoom, ...obj }; // 合并更新
    },
  },
  actions: {},
});
